﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CustomerManage_affiliate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("300400104");
        if (!IsPostBack)
        {
            ShowRecommend();
            setRecommend();
        }
        
    }
    //等级列表
    public void ShowRecommend()
    {
        dlistOrderDetail.DataSource = new BLL.RecommendLevelSet().GetAllList();
        dlistOrderDetail.DataBind();
    }
    //显示等级初始设置
    public void setRecommend()
    {
            foreach (Model.IntergalTypeSet IntergalTypeSetModel in new BLL.IntergalTypeSet().GetAllList())
            {
                txtInergalTypeEndDateTime.Text = IntergalTypeSetModel.InergalTypeEndDateTime.ToString();
                txtIntergalSetExtendAttribute5.Text = IntergalTypeSetModel.IntergalSetExtendAttribute5.ToString();
                txtIntergalSetExtendAttribute2.Text = IntergalTypeSetModel.IntergalSetExtendAttribute2;
                txtIntergalSetExtendAttribute3.Text = IntergalTypeSetModel.IntergalSetExtendAttribute3;
                txtInergal.Text = IntergalTypeSetModel.IntergalSetExtendAttribute7.ToString();
                txtInergalRadio.Text = IntergalTypeSetModel.InergalRadio.ToString();
                //ddlInergalTypeUnit.SelectedValue = IntergalTypeSetModel.InergalTypeUnit.Trim().ToString();
                TextBox1.Text = IntergalTypeSetModel.IntergalSetEffact.ToString();
                TextBox2.Text = IntergalTypeSetModel.IntergalSetExtendAttribute6.ToString();
            }
    
    }


    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        if (Check.CheckPermission("300400104", "00001"))
        {
            Model.RecommendLevelSet RecommendLevelSetmodel = new Model.RecommendLevelSet();
            RecommendLevelSetmodel.RecommendId = Guid.NewGuid().ToString();
            RecommendLevelSetmodel.RecommendInergalSeparate = 0;
            RecommendLevelSetmodel.RecommendCostSeparate = 0;
            RecommendLevelSetmodel.RecommendManLevel = 0;
            new BLL.RecommendLevelSet().Add(RecommendLevelSetmodel);
            ShowRecommend();
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        
    }
    protected void btnAllSave_Click(object sender, EventArgs e)
    {



        if (new BLL.IntergalTypeSet().GetAllList().Count > 0)
        {


            foreach (Model.IntergalTypeSet IntergalTypeSetModel in new BLL.IntergalTypeSet().GetAllList())
            {
                IntergalTypeSetModel.InergalTypeEndDateTime = Convert.ToDecimal(txtInergalTypeEndDateTime.Text);
                IntergalTypeSetModel.IntergalSetExtendAttribute5 = Convert.ToInt32(txtIntergalSetExtendAttribute5.Text);
                IntergalTypeSetModel.IntergalSetExtendAttribute2 = txtIntergalSetExtendAttribute2.Text.Trim().Length > 0 ? txtIntergalSetExtendAttribute2.Text : "0";
                IntergalTypeSetModel.IntergalSetExtendAttribute3 = txtIntergalSetExtendAttribute3.Text.Trim().Length > 0 ? txtIntergalSetExtendAttribute3.Text : "0";
                IntergalTypeSetModel.IntergalSetExtendAttribute7 = Convert.ToDecimal(txtInergal.Text);
                IntergalTypeSetModel.InergalRadio = Convert.ToDecimal(txtInergalRadio.Text);
                IntergalTypeSetModel.IntergalSetEffact = TextBox1.Text.Trim().Length>0?DateTime.Parse(TextBox1.Text):DateTime.MinValue;
                //IntergalTypeSetModel.InergalTypeUnit  =  ddlInergalTypeUnit.SelectedValue;
                IntergalTypeSetModel.IntergalSetExtendAttribute6 = TextBox2.Text.Trim().Length > 0 ? int.Parse(TextBox2.Text.Trim()) : 0;
                new BLL.IntergalTypeSet().Update(IntergalTypeSetModel);
            }
        }
        else
        {
            Model.IntergalTypeSet IntergalTypeSetModel = new Model.IntergalTypeSet();
            IntergalTypeSetModel.InergalTypeId = Guid.NewGuid().ToString();
            IntergalTypeSetModel.InergalTypeEndDateTime = Convert.ToDecimal(txtInergalTypeEndDateTime.Text);
            IntergalTypeSetModel.IntergalSetExtendAttribute5 = Convert.ToInt32(txtIntergalSetExtendAttribute5.Text);
            IntergalTypeSetModel.IntergalSetExtendAttribute2 = txtIntergalSetExtendAttribute2.Text.Trim().Length > 0 ? txtIntergalSetExtendAttribute2.Text : "0";
            IntergalTypeSetModel.IntergalSetExtendAttribute3 = txtIntergalSetExtendAttribute3.Text.Trim().Length > 0 ? txtIntergalSetExtendAttribute3.Text : "0";
            IntergalTypeSetModel.IntergalSetExtendAttribute7 = Convert.ToInt32(txtInergal.Text);
            IntergalTypeSetModel.InergalRadio = Convert.ToInt32(txtInergalRadio.Text);
            //IntergalTypeSetModel.InergalTypeUnit = ddlInergalTypeUnit.SelectedValue;
            IntergalTypeSetModel.IntergalSetEffact = TextBox1.Text.Trim().Length > 0 ? DateTime.Parse(TextBox1.Text) : DateTime.MinValue;
            IntergalTypeSetModel.IntergalSetExtendAttribute6 = TextBox2.Text.Trim().Length > 0 ? int.Parse(TextBox2.Text.Trim()) : 0;
            new BLL.IntergalTypeSet().Add(IntergalTypeSetModel);
        
        }

        setRecommend();

    }
    protected void dlistOrderDetail_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "del")
        {
            if (Check.CheckPermission("300400104", "00003"))
            {
                TextBox txtRecommendId = (TextBox)e.Item.FindControl("txtRecommendId");
                new BLL.RecommendLevelSet().Delete(txtRecommendId.Text);
                ShowRecommend();
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            

        }


        if (e.CommandName.ToLower() == "update")
        {
            if (Check.CheckPermission("300400104", "00002"))
            {
                TextBox txtRecommendId = (TextBox)e.Item.FindControl("txtRecommendId");
                TextBox txtRecommendInergalSeparate = (TextBox)e.Item.FindControl("txtRecommendInergalSeparate");
                TextBox txtRecommendCostSeparate = (TextBox)e.Item.FindControl("txtRecommendCostSeparate");
                TextBox TxtRecommendManLevel = (TextBox)e.Item.FindControl("TxtRecommendManLevel");
                TextBox txtValidDate = (TextBox)e.Item.FindControl("txtValidDate");
                TextBox lmjf = (TextBox)e.Item.FindControl("TextBox3");  //联盟积分分成
                TextBox lmxj = (TextBox)e.Item.FindControl("TextBox4");  //联盟现金分成

                Model.RecommendLevelSet RecommendLevelSetmodel = new BLL.RecommendLevelSet().GetModel(txtRecommendId.Text);
                RecommendLevelSetmodel.RecommendInergalSeparate = Convert.ToDecimal(txtRecommendInergalSeparate.Text);
                RecommendLevelSetmodel.RecommendCostSeparate = Convert.ToDecimal(txtRecommendCostSeparate.Text);
                RecommendLevelSetmodel.RecommendManLevel = Convert.ToInt32(TxtRecommendManLevel.Text);
                RecommendLevelSetmodel.Attribute5 = Convert.ToInt32(txtValidDate.Text);
                RecommendLevelSetmodel.Attribute7 = Convert.ToInt32(lmjf.Text);
                RecommendLevelSetmodel.Attribute8 = Convert.ToInt32(lmxj.Text);
                new BLL.RecommendLevelSet().Update(RecommendLevelSetmodel);
                ShowRecommend();
            }
            else
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
           



        }



    }
    protected void dlistOrderDetail_ItemDataBound(object sender, DataListItemEventArgs e)
    {

    }
}
